package com.hethongviet.job.helpers.listadapter;

import java.util.List;
 
import com.hethongviet.job.R;
import com.hethongviet.job.models.Project;
 
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
  
public class ListItemProjectAdapter extends ArrayAdapter<Project>
{
	private final List<Project>	values;
	private final Activity			activity;

	/* Make higher performance */
	private static class ViewHolder
	{
		public TextView		_textProjectName;
		public TextView		_textProjectWorker;
		public TextView		_textProjectDateCreated;
	}

	public ListItemProjectAdapter(Activity activity, List<Project> values)
	{
		super(activity, R.layout.list_item_project, values);
		this.values = values;
		this.activity = activity;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View rowView = convertView;
		final ViewHolder viewHolder;

		if (rowView == null)
		{
			LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = layoutInflater.inflate(R.layout.list_item_project, parent, false);
			viewHolder = new ViewHolder();
			viewHolder._textProjectDateCreated = (TextView) rowView.findViewById(R.id.textProjectDateCreated);
			viewHolder._textProjectName = (TextView) rowView.findViewById(R.id.textProjectName);
			viewHolder._textProjectWorker= (TextView) rowView.findViewById(R.id.textProjectWorker);
			rowView.setTag(viewHolder);
		}
		else
		{
			viewHolder = (ViewHolder) rowView.getTag();
		}
		/*Initiate items*/
		final Project currentProject = values.get(position);
		viewHolder._textProjectDateCreated.setText(activity.getString(R.string.textDateCreated) +" "+ currentProject.getDateCreated());
		viewHolder._textProjectName.setText(currentProject.getName());
		viewHolder._textProjectWorker.setText(activity.getString(R.string.textProjectWorker) +" "+ currentProject.getWorker());
		
		/*Return view*/
		return rowView;
	}
}
